package com.hankol.feature_wine_meal.adapter

import com.baselibrary.utils.GlideUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.feature_wine_meal.R
import com.hankol.feature_wine_meal.bean.FoodDetailsBean
import com.hankol.feature_wine_meal.bean.MainFood

/**
 * @author: 关忆北、
 * @date: 2022/6/21
 * @Des：时令美食-列表
 */
class FineFoodAdapter : BaseQuickAdapter<FoodDetailsBean, BaseViewHolder>(R.layout.item_find_food_list) {
    override fun convert(helper: BaseViewHolder, item: FoodDetailsBean) {
        helper.setText(R.id.tv_findFood_name, item.name)
                .setText(R.id.tv_findFood_major, "${item.mainFood.size}种主料 · ${item.nanYiDu} · ${item.cookTime}")
                .setText(R.id.tv_findFood_content, getTotalMaterial(item.mainFood, item.secondFood))
        GlideUtils.loadImg_101(mContext.applicationContext, item.cover, helper.getView(R.id.round_findFood_cover))
    }

    fun getTotalMaterial(mainFood: List<MainFood>, secondFood: List<MainFood>): String {
        val buffer = StringBuffer()
        mainFood.forEach { mainIt ->
            buffer.append(mainIt.name)
                    .append("、")
        }
        secondFood.forEach { secondIt ->
            buffer.append(secondIt.name)
                    .append("、")
        }
        buffer.deleteCharAt(buffer.length - 1)
        return buffer.toString()
    }
}